﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dunnice.BlogIndex.Entity;

namespace Dunnice.BlogIndex.BLL.LocalSiteStorage
{
    /// <summary>
    /// 制作html页面,输出html字符串.
    /// </summary>
    public class PageMaker
    {
        /// <summary>
        /// 制作博客文章页面
        /// </summary>
        /// <param name="article"></param>
        /// <returns></returns>
        public static string MakeArticlePage(BlogArticleInfo article)
        {
            StringBuilder pageBui = new StringBuilder();
            pageBui.AppendFormat(@"<html>
<head>
    <meta http-equiv=""Content-Type"" content=""text/html; charset=GBK"">
    <title>{0}</title>
    <style type=""text/css"">
        a{{color: #000000;text-decoration: none;font-size: 10pt;}}
        a:hover{{color: red;text-decoration: underline;}}
    </style>
</head>
<body>
<h2><a href=""{1}"" target=_blank>[原网页]</a>{0}</h2>", article.Title, article.Url);

            pageBui.Append(article.Content);

            pageBui.Append(@"</body></html>");

            return pageBui.ToString();
        }

        /// <summary>
        /// 制作单个作者的博客索引页.
        /// </summary>
        /// <param name="author"></param>
        /// <param name="articlePages"></param>
        /// <returns></returns>
        public static string MakeArticleIndexPage(BlogAuthorInfo author, List<LocalPageInfo> articlePages)
        {
            StringBuilder indexBui = new StringBuilder();

            indexBui.AppendFormat(@"<html>
<head>
<meta http-equiv=""Content-Type"" content=""text/html; charset=GBK"">
<title>{0}的博客文章</title>
<style type=""text/css"">
body{{font-size: 16pt;}}
a{{color: #000000;text-decoration : none;font-size: 10pt;}}
a:hover {{color: red;text-decoration : underline;}}
</style>
</head>
<body>
<h2><a href=""{1}"" target=_blank>[原网页]</a>{0}的博客文章</h2>
<table>
", author.AuthorName, author.BlogUrl);

            foreach (LocalPageInfo pageInfo in articlePages)
            {
                indexBui.AppendFormat(
    @"<tr><td>({0})</td><td><a href=""{1}"" target=_blank>[原网页]</a></td><td><a href=""{2}"">{3}</a></td></tr>",
                     pageInfo.PagePublishTime, pageInfo.PageBlogUrl, pageInfo.PageName, pageInfo.ArticleName);
            }

            indexBui.Append(@"</table></body></html>");

            return indexBui.ToString();
        }

        /// <summary>
        /// 制作分类作者索引页.
        /// </summary>
        /// <param name="sites"></param>
        /// <returns></returns>
        public static string MakeCategoryAuthorIndexPage(List<LocalSiteInfo> sites)
        {
            StringBuilder indexBui = new StringBuilder();

            indexBui.Append(@"<html>
<head>
<meta http-equiv=""Content-Type"" content=""text/html; charset=GBK"">
<title>分类：博客园 的博客</title>
<style type=""text/css"">
body{{font-size: 16pt;}}
a{(color: #000000;text-decoration : none;font-size: 10pt;})
a:hover {{color: red;text-decoration : underline;}{
</style>
</head>
<body>
<h2>分类：博客园 的博客</h2>
<table>");

            foreach (LocalSiteInfo site in sites)
            {
                indexBui.AppendFormat(
    @"<tr><td><a href=""{0}"" target=_blank>[原网页]</a></td><td><a href=""{1}/index.html"">{1}</a></td></tr>",
                 site.AuthroBolgHostUrl, site.AuthorName);
            }

            indexBui.Append(@"</table> </body> </html>");

            return indexBui.ToString();
        }
    }
}
